<?php


namespace app\controller\archives;
require_once __DIR__.'/../../common/AuthController.php';
use app\common\AuthController;


/**
 * 地区
 */
class Region extends AuthController
{   


    /**
     * 初始化操作
     */
    public function init()
    {

    }
	

    /**
     * 获取地区列表
     */
	public function api_archives_region_getList($msg)
    {   
        global $db;
        $page = isset($msg['data']['page'])?$msg['data']['page']:1;
        $rows = isset($msg['data']['rows'])?$msg['data']['rows']:15;
        $data = [
           'id' => isset($msg['data']['id'])?$msg['data']['id']:'',
           'region_type' => isset($msg['data']['region_type'])?$msg['data']['region_type']:'',
           'region_name' => isset($msg['data']['region_name'])?$msg['data']['region_name']:'',
           'select_type' => isset($msg['data']['select_type'])?$msg['data']['select_type']:'',
        ];
        $limit = ($page-1)*$rows.','.$rows;
        $where = 'country_id = 100000 ';
        if(!empty($data['id'])){
            $where .= " AND id =".$data['id'];
        }
        if(!empty($data['region_type'])){
            $where .= " AND region_type =".$data['region_type'];
        }
        if(!empty($data['region_name'])){
            $where .= " AND region_name LIKE '%".$data['region_name']."%'";
        }
        if(empty($data['select_type'])){
            $res = $db->query("SELECT * from region WHERE ".$where." limit ".$limit);
        }else{
            $res = $db->query("SELECT id,region_name from region WHERE ".$where." limit ".$limit);
        }
        $count =  $db->query("SELECT count(*) as count from region WHERE ".$where);
		return $this->outMessage(10000,'获取成功',$res,'success',$count[0]['count']);
	}




 

}
